using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PathUtil 
{
    //根目录   
    public static readonly string AssetPath = Application.dataPath;

    //需要打bundle的目录
    //public static readonly string BuildResourcesPath = Application.dataPath + "/Buildresources";      这种写法在多次访问的时候Application.dataPath容易产生GC
    public static readonly string BuildResourcesPath = AssetPath + "/BuildResources/";

    //bundle输出目录
    public static readonly string BuildOutPath = Application.streamingAssetsPath;

    //只读目录
    public static readonly string ReadPath = Application.streamingAssetsPath;

    //可读写目录
    public static readonly string ReadAndWritePath = Application.persistentDataPath;

    //Lua路径
    public static readonly string LuaPath = "Assets/BuildResources/LuaScripts";

    //bundle资源路径
    public static string BundleResourcePath
    {
        get {
            if (AppConst.GameMode == GameMode.UpdateMode)
                return ReadAndWritePath;
            return ReadPath; 
        }
    }


    /// <summary>
    /// 获取Unity相对路径
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static string GetUnityPath(string path)
    {
        if(string.IsNullOrEmpty(path))
            return string.Empty;

        return path.Substring(path.IndexOf("Assets"));
    }

    /// <summary>
    /// 获取标准路径,避免路径出现反斜杠
    /// </summary>
    /// <param name="path"></param>
    public static string GetStandardPath(string path)
    {
        if(string.IsNullOrEmpty (path)) return string.Empty; 

        return path.Trim().Replace("\\", "/"); 
    }

    public static string GetUIPath(string name)
    {
        return string.Format("Assets/BuildResources/UI/Prefabs/{0}.prefab", name);
    }

    public static string GetLuaPath(string name)
    {
        return string.Format("Assets/BuildResources/LuaScripts/{0}.bytes", name);
    }

    public static string GetModelPath(string name)
    {
        return string.Format("Assets/BuildResources/Model/Prefabs/{0}.prefab", name);
    }

    public static string GetEffectPath(string name)
    {
        return string.Format("Assets/BuildResources/Effect/Prefabs/{0}.prefab", name);
    }

    public static string GetScenePath(string name)
    {
        return string.Format("Assets/BuildResources/Scene/{0}.unity", name);
    }

    public static string GetMusicPath(string name)
    {
        return string.Format("Assets/BuildResources/Audio/BGM/{0}", name);
    }

    public static string GetSoundEffectPath(string name)
    {
        return string.Format("Assets/BuildResources/Audio/SoundEffect/{0}", name);
    }
}
